package SoftwarePrinciple.DependencyInversionPrinciple;

/**
 * @author: Themberfue
 * @date: 2025/8/7 11:54
 * @description:
 */
// 客户端代码
public class Client {
    public static void main(String[] args) {
        // 可以灵活切换不同的消息服务实现
        MessageService emailService = new EmailService();
        Notification emailNotification = new Notification(emailService);
        emailNotification.notifyUser("欢迎注册！", "user@example.com");

        // 新增微信服务时，无需修改Notification类
        MessageService wechatService = new WechatService();
        Notification wechatNotification = new Notification(wechatService);
        wechatNotification.notifyUser("欢迎注册！", "wechat_user123");
    }
}

// 新增的微信服务实现（无需修改现有代码）
class WechatService implements MessageService {
    @Override
    public void sendMessage(String content, String recipient) {
        System.out.println("发送微信给 " + recipient + ": " + content);
    }
}

